﻿// $Id: _Framework.cs 10 2008-02-29 15:58:02Z mcartoixa $
/*! \file
 * \brief Definition of Compact Framework specific classes.
 *
 * \author $Author: mcartoixa $
 * \date $Date: 2008-02-29 16:58:02 +0100 (ven., 29 févr. 2008) $
 * \version $Revision: 10 $
 */

#if (NET_CF)
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using Salamanca.Resources;

namespace Salamanca
{

    /// <summary>Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime.</summary>
    public static class Array
    {
        /// <summary>Converts an array of one type to an array of another type.</summary>
        /// <returns>An array of the target type containing the converted elements from the source array.</returns>
        /// <param name="array">The one-dimensional, zero-based <see cref="T:System.Array"></see> to convert to a target type.</param>
        /// <param name="converter">A <see cref="T:System.Converter`2"></see> that converts each element from one type to another type.</param>
        /// <exception cref="T:System.ArgumentNullException">array is null.-or-converter is null.</exception>
        public static TOutput[] ConvertAll<TInput, TOutput>(TInput[] array, Converter<TInput, TOutput> converter)
        {
            if (array==null)
            {
                throw new ArgumentNullException("array");
            }
            if (converter==null)
            {
                throw new ArgumentNullException("converter");
            }
            TOutput[] localArray1=new TOutput[array.Length];
            for (int num1=0; num1<array.Length; num1++)
            {
                localArray1[num1]=converter(array[num1]);
            }
            return localArray1;
        }

        /// <summary>Retrieves all the elements that match the conditions defined by the specified predicate.</summary>
        /// <returns>An <see cref="T:System.Array"></see> containing all the elements that match the conditions defined by the specified predicate, if found; otherwise, an empty <see cref="T:System.Array"></see>.</returns>
        /// <param name="array">The one-dimensional, zero-based <see cref="T:System.Array"></see> to search.</param>
        /// <param name="match">The <see cref="T:System.Predicate`1"></see> that defines the conditions of the elements to search for.</param>
        /// <exception cref="T:System.ArgumentNullException">array is null.-or-match is null.</exception>
        public static T[] FindAll<T>(T[] array, Predicate<T> match)
        {
            if (array==null)
            {
                throw new ArgumentNullException("array");
            }
            if (match==null)
            {
                throw new ArgumentNullException("match");
            }
            List<T> list1=new List<T>();
            for (int num1=0; num1<array.Length; num1++)
            {
                if (match(array[num1]))
                {
                    list1.Add(array[num1]);
                }
            }
            return list1.ToArray();
        }

        /// <summary>Performs the specified action on each element of the specified array.</summary>
        /// <param name="array">The one-dimensional, zero-based <see cref="T:System.Array"></see> on whose elements the action is to be performed.</param>
        /// <param name="action">The <see cref="T:System.Action`1"></see> to perform on each element of array.</param>
        /// <exception cref="T:System.ArgumentNullException">array is null.-or-action is null.</exception>
        public static void ForEach<T>(T[] array, Action<T> action)
        {
            if (array==null)
            {
                throw new ArgumentNullException("array");
            }
            if (action==null)
            {
                throw new ArgumentNullException("action");
            }
            for (int num1=0; num1<array.Length; num1++)
            {
                action(array[num1]);
            }
        }
    }
}

namespace System.Runtime.CompilerServices
{

    /// <summary>Distinguishes a compiler-generated element from a user-generated element. This class cannot be inherited.</summary>
    public sealed class CompilerGeneratedAttribute:
        Attribute
    {
    }
}

namespace System.CodeDom.Compiler
{
    /// <summary>Represents a collection of temporary files.</summary>
    public class TempFileCollection:
        ICollection,
        IEnumerable,
        IDisposable
    {
        static TempFileCollection()
        {
            TempFileCollection.rng=new RNGCryptoServiceProvider();
        }

        /// <summary>Initializes a new instance of the <see cref="T:System.CodeDom.Compiler.TempFileCollection"></see> class with default values.</summary>
        public TempFileCollection()
            :
            this(null, false)
        {
        }

        /// <summary>Initializes a new instance of the <see cref="T:System.CodeDom.Compiler.TempFileCollection"></see> class using the specified temporary directory that is set to delete the temporary files after their generation and use, by default.</summary>
        /// <param name="tempDir">A path to the temporary directory to use for storing the temporary files. </param>
        public TempFileCollection(string tempDir)
            :
            this(tempDir, false)
        {
        }

        /// <summary>Initializes a new instance of the <see cref="T:System.CodeDom.Compiler.TempFileCollection"></see> class using the specified temporary directory and specified value indicating whether to keep or delete the temporary files after their generation and use, by default.</summary>
        /// <param name="tempDir">A path to the temporary directory to use for storing the temporary files. </param>
        /// <param name="keepFiles">true if the temporary files should be kept after use; false if the temporary files should be deleted. </param>
        public TempFileCollection(string tempDir, bool keepFiles)
        {
            this.keepFiles=keepFiles;
            this.tempDir=tempDir;
            this.files=new Hashtable(StringComparer.OrdinalIgnoreCase);
        }

        /// <summary>Adds a file name with the specified file name extension to the collection.</summary>
        /// <returns>A file name with the specified extension that was just added to the collection.</returns>
        /// <param name="fileExtension">The file name extension for the auto-generated temporary file name to add to the collection. </param>
        public string AddExtension(string fileExtension)
        {
            return this.AddExtension(fileExtension, this.keepFiles);
        }

        /// <summary>Adds a file name with the specified file name extension to the collection, using the specified value indicating whether the file should be deleted or retained.</summary>
        /// <returns>A file name with the specified extension that was just added to the collection.</returns>
        /// <param name="keepFile">true if the file should be kept after use; false if the file should be deleted. </param>
        /// <param name="fileExtension">The file name extension for the auto-generated temporary file name to add to the collection. </param>
        /// <exception cref="T:System.ArgumentException">fileExtension is null or an empty string.</exception>
        public string AddExtension(string fileExtension, bool keepFile)
        {
            if ((fileExtension==null)||(fileExtension.Length==0))
            {
                throw new ArgumentException(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        SR.InvalidNullEmptyArgument,
                        "fileExtension"
                    ),
                    "fileExtension"
                );
            }
            string text1=this.BasePath+"."+fileExtension;
            this.AddFile(text1, keepFile);
            return text1;
        }

        /// <summary>Adds the specified file to the collection, using the specified value indicating whether to keep the file after the collection is disposed or when the <see cref="M:System.CodeDom.Compiler.TempFileCollection.Delete"></see> method is called.</summary>
        /// <param name="fileName">The name of the file to add to the collection. </param>
        /// <param name="keepFile">true if the file should be kept after use; false if the file should be deleted. </param>
        /// <exception cref="T:System.ArgumentException">fileName is null or an empty string.-or-fileName is a duplicate.</exception>
        public void AddFile(string fileName, bool keepFile)
        {
            if ((fileName==null)||(fileName.Length==0))
            {
                throw new ArgumentException(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        SR.InvalidNullEmptyArgument,
                        "fileName"
                    ),
                    "fileName"
                );
            }
            if (this.files[fileName]!=null)
            {
                throw new ArgumentException(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        SR.DuplicateFileName,
                        fileName
                    ),
                    "fileName"
                );
            }
            this.files.Add(fileName, keepFile);
        }

        /// <summary>Copies the members of the collection to the specified string, beginning at the specified index.</summary>
        /// <param name="fileNames">The array of strings to copy to. </param>
        /// <param name="start">The index of the array to begin copying to. </param>
        public void CopyTo(string[] fileNames, int start)
        {
            this.files.Keys.CopyTo(fileNames, start);
        }

        /// <summary>Deletes the temporary files within this collection that were not marked to be kept.</summary>
        public void Delete()
        {
            if (this.files!=null)
            {
                string[] textArray1=new string[this.files.Count];
                this.files.Keys.CopyTo(textArray1, 0);
                foreach (string text1 in textArray1)
                {
                    if (!this.KeepFile(text1))
                    {
                        this.Delete(text1);
                        this.files.Remove(text1);
                    }
                }
            }
        }

        private void Delete(string fileName)
        {
            try
            {
                File.Delete(fileName);
            } catch
            {
            }
        }

        /// <summary>Releases the unmanaged resources used by the <see cref="T:System.CodeDom.Compiler.TempFileCollection"></see> and optionally releases the managed resources.</summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources. </param>
        protected virtual void Dispose(bool disposing)
        {
            this.Delete();
        }

        private void EnsureTempNameCreated()
        {
            if (this.basePath==null)
            {
                string text1=null;
                bool flag1=false;
                int num1=0x1388;
                do
                {
                    try
                    {
                        this.basePath=TempFileCollection.GetTempFileName(this.TempDir);
                        text1=this.basePath+".tmp";
                        using (FileStream stream1=new FileStream(text1, FileMode.CreateNew, FileAccess.Write))
                        {
                        }
                        flag1=true;
                    } catch (IOException exception1)
                    {
                        num1--;
                        if ((num1==0)||(Marshal.GetHRForException(exception1)!=80))
                        {
                            throw;
                        }
                        flag1=false;
                    }
                }
                while (!flag1);
                this.files.Add(text1, this.keepFiles);
            }
        }

        /// <summary>Attempts to delete the temporary files before this object is reclaimed by garbage collection.</summary>
        ~TempFileCollection()
        {
            this.Dispose(false);
        }

        private static string GenerateRandomFileName()
        {
            byte[] buffer1=new byte[6];
            lock (TempFileCollection.rng)
            {
                TempFileCollection.rng.GetBytes(buffer1);
            }
            string text1=Convert.ToBase64String(buffer1).ToLower(CultureInfo.InvariantCulture);
            return text1.Replace('/', '-').Replace('+', '_');
        }

        /// <summary>Gets an enumerator that can enumerate the members of the collection.</summary>
        /// <returns>An <see cref="T:System.Collections.IEnumerator"></see> that contains the collection's members.</returns>
        public IEnumerator GetEnumerator()
        {
            return this.files.Keys.GetEnumerator();
        }

        private static string GetTempFileName(string tempDir)
        {
            if ((tempDir==null)||(tempDir.Length==0))
            {
                tempDir=Path.GetTempPath();
            }
            string text1=TempFileCollection.GenerateRandomFileName();
            if (tempDir.EndsWith(@"\", StringComparison.Ordinal))
            {
                return (tempDir+text1);
            }
            return (tempDir+@"\"+text1);
        }

        private bool KeepFile(string fileName)
        {
            object obj1=this.files[fileName];
            if (obj1==null)
            {
                return false;
            }
            return (bool)obj1;
        }

        internal void SafeDelete()
        {
            this.Delete();
        }

        void ICollection.CopyTo(Array array, int start)
        {
            this.files.Keys.CopyTo(array, start);
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.files.Keys.GetEnumerator();
        }

        void IDisposable.Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }


        /// <summary>Gets the full path to the base file name, without a file name extension, on the temporary directory path, that is used to generate temporary file names for the collection.</summary>
        /// <returns>The full path to the base file name, without a file name extension, on the temporary directory path, that is used to generate temporary file names for the collection.</returns>
        /// <exception cref="T:System.Security.SecurityException">If the <see cref="P:System.CodeDom.Compiler.TempFileCollection.BasePath"></see> property has not been set or is set to null, and <see cref="F:System.Security.Permissions.FileIOPermissionAccess.AllAccess"></see> is not granted for the temporary directory indicated by the <see cref="P:System.CodeDom.Compiler.TempFileCollection.TempDir"></see> property. </exception>
        public string BasePath
        {
            get
            {
                this.EnsureTempNameCreated();
                return this.basePath;
            }
        }

        /// <summary>Gets the number of files in the collection.</summary>
        /// <returns>The number of files in the collection.</returns>
        public int Count
        {
            get
            {
                return this.files.Count;
            }
        }

        /// <summary>Gets or sets a value indicating whether to keep the files, by default, when the <see cref="M:System.CodeDom.Compiler.TempFileCollection.Delete"></see> method is called or the collection is disposed.</summary>
        /// <returns>true if the files should be kept; otherwise, false.</returns>
        public bool KeepFiles
        {
            get
            {
                return this.keepFiles;
            }
            set
            {
                this.keepFiles=value;
            }
        }

        int ICollection.Count
        {
            get
            {
                return this.files.Count;
            }
        }

        bool ICollection.IsSynchronized
        {
            get
            {
                return false;
            }
        }

        object ICollection.SyncRoot
        {
            get
            {
                return null;
            }
        }

        /// <summary>Gets the temporary directory to store the temporary files in.</summary>
        /// <returns>The temporary directory to store the temporary files in.</returns>
        public string TempDir
        {
            get
            {
                if (this.tempDir!=null)
                {
                    return this.tempDir;
                }
                return string.Empty;
            }
        }


        private string basePath;
        private Hashtable files;
        private bool keepFiles;
        private static RNGCryptoServiceProvider rng;
        private string tempDir;
    }
}

namespace System.ComponentModel.Design.Serialization
{

    /// <summary>Provides the information necessary to create an instance of an object. This class cannot be inherited.</summary>
    public sealed class InstanceDescriptor
    {

        /// <summary>Initializes a new instance of the <see cref="T:System.ComponentModel.Design.Serialization.InstanceDescriptor"></see> class using the specified member information, arguments, and value indicating whether the specified information completely describes the instance.</summary>
        /// <param name="member">The member information for the descriptor. This can be a <see cref="T:System.Reflection.MethodInfo"></see>, <see cref="T:System.Reflection.ConstructorInfo"></see>, <see cref="T:System.Reflection.FieldInfo"></see>, or <see cref="T:System.Reflection.PropertyInfo"></see>. If this is a <see cref="T:System.Reflection.MethodInfo"></see>, <see cref="T:System.Reflection.FieldInfo"></see>, or <see cref="T:System.Reflection.PropertyInfo"></see>, it must represent a static member. </param>
        /// <param name="arguments">The collection of arguments to pass to the member. This parameter can be null or an empty collection if there are no arguments. The collection can also consist of other instances of <see cref="T:System.ComponentModel.Design.Serialization.InstanceDescriptor"></see>. </param>
        /// <param name="isComplete">true if the specified information completely describes the instance; otherwise, false. </param>
        /// <exception cref="T:System.ArgumentException">member is of type <see cref="T:System.Reflection.MethodInfo"></see>, <see cref="T:System.Reflection.FieldInfo"></see>, or <see cref="T:System.Reflection.PropertyInfo"></see>, and it does not represent a static membermember is of type <see cref="T:System.Reflection.PropertyInfo"></see> and is not readable.member is of type <see cref="T:System.Reflection.MethodInfo"></see> or <see cref="T:System.Reflection.ConstructorInfo"></see> and the number of arguments in arguments does not match the signature of member.member is of type <see cref="T:System.Reflection.ConstructorInfo"></see> and represents a static membermember is of type <see cref="T:System.Reflection.FieldInfo"></see>, and the number of arguments in arguments is not zero.</exception>
        public InstanceDescriptor(MemberInfo member, ICollection arguments, bool isComplete)
        {
            _Member=member;
            _Arguments=arguments;
            _IsComplete=isComplete;
        }

        /// <summary>Initializes a new instance of the <see cref="T:System.ComponentModel.Design.Serialization.InstanceDescriptor"></see> class using the specified member information and arguments.</summary>
        /// <param name="member">The member information for the descriptor. This can be a <see cref="T:System.Reflection.MethodInfo"></see>, <see cref="T:System.Reflection.ConstructorInfo"></see>, <see cref="T:System.Reflection.FieldInfo"></see>, or <see cref="T:System.Reflection.PropertyInfo"></see>. If this is a <see cref="T:System.Reflection.MethodInfo"></see>, <see cref="T:System.Reflection.FieldInfo"></see>, or <see cref="T:System.Reflection.PropertyInfo"></see>, it must represent a static member. </param>
        /// <param name="arguments">The collection of arguments to pass to the member. This parameter can be null or an empty collection if there are no arguments. The collection can also consist of other instances of <see cref="T:System.ComponentModel.Design.Serialization.InstanceDescriptor"></see>. </param>
        /// <exception cref="ArgumentException">member is of type <see cref="MethodInfo"></see>, <see cref="FieldInfo"></see>, or <see cref="PropertyInfo"></see>, and it does not represent a static member.member is of type <see cref="PropertyInfo"></see> and is not readable.member is of type <see cref="MethodInfo"></see> or <see cref="ConstructorInfo"></see>, and the number of arguments in arguments does not match the signature of member.member is of type <see cref="ConstructorInfo"></see> and represents a static member.member is of type <see cref="FieldInfo"></see>, and the number of arguments in arguments is not zero. </exception>
        public InstanceDescriptor(MemberInfo member, ICollection arguments):
            this(member, arguments, true)
        {
        }

        /// <summary>Invokes this instance descriptor and returns the object the descriptor describes.</summary>
        /// <returns>The object this instance descriptor describes.</returns>
        public object Invoke()
        {
            object[] objArray1=new object[_Arguments.Count];
            _Arguments.CopyTo(objArray1, 0);
            for (int num1=0; num1<objArray1.Length; ++num1)
            {
                if (objArray1[num1] is InstanceDescriptor)
                  objArray1[num1]=((InstanceDescriptor)objArray1[num1]).Invoke();
            }
            if (_Member is ConstructorInfo)
                return ((ConstructorInfo)_Member).Invoke(objArray1);
            if (_Member is MethodInfo)
                return ((MethodInfo)_Member).Invoke(null, objArray1);
            if (_Member is PropertyInfo)
                return ((PropertyInfo)_Member).GetValue(null, objArray1);
            if (_Member is FieldInfo)
                return ((FieldInfo)_Member).GetValue(null);
            return null;
        }

        /// <summary>Gets the collection of arguments that can be used to reconstruct an instance of the object that this instance descriptor represents.</summary>
        /// <returns>An <see cref="T:System.Collections.ICollection"></see> of arguments that can be used to create the object.</returns>
        public ICollection Arguments
        {
            get
            {
                return _Arguments;
            }
        }

        /// <summary>Gets a value indicating whether the contents of this <see cref="T:System.ComponentModel.Design.Serialization.InstanceDescriptor"></see> completely identify the instance.</summary>
        /// <returns>true if the instance is completely described; otherwise, false.</returns>
        public bool IsComplete
        {
            get
            {
                return _IsComplete;
            }
        }


        /// <summary>Gets the member information that describes the instance this descriptor is associated with.</summary>
        /// <returns>A <see cref="T:System.Reflection.MemberInfo"></see> that describes the instance that this object is associated with.</returns>
        public MemberInfo MemberInfo
        {
            get
            {
                return _Member;
            }
        }

        private ICollection _Arguments;
        private bool _IsComplete;
        private MemberInfo _Member;
    }
}

namespace System.ComponentModel
{
    using System.ComponentModel.Design.Serialization;

    /// <summary>Provides contextual information about a component, such as its container and property descriptor.</summary>
    public interface ITypeDescriptorContext:
        IServiceProvider
    {

        /// <summary>Raises the <see cref="E:System.ComponentModel.Design.IComponentChangeService.ComponentChanged"></see> event.</summary>
        void OnComponentChanged();

        /// <summary>Raises the <see cref="E:System.ComponentModel.Design.IComponentChangeService.ComponentChanging"></see> event.</summary>
        /// <returns>true if this object can be changed; otherwise, false.</returns>
        bool OnComponentChanging();

        /// <summary>Gets the container representing this <see cref="T:System.ComponentModel.TypeDescriptor"></see> request.</summary>
        /// <returns>An <see cref="T:System.ComponentModel.IContainer"></see> with the set of objects for this <see cref="T:System.ComponentModel.TypeDescriptor"></see>; otherwise, null if there is no container or if the <see cref="T:System.ComponentModel.TypeDescriptor"></see> does not use outside objects.</returns>
        IContainer Container
        {
            get;
        }

        /// <summary>Gets the object that is connected with this type descriptor request.</summary>
        /// <returns>The object that invokes the method on the <see cref="T:System.ComponentModel.TypeDescriptor"></see>; otherwise, null if there is no object responsible for the call.</returns>
        object Instance
        {
            get;
        }

        /// <summary>Gets the <see cref="T:System.ComponentModel.PropertyDescriptor"></see> that is associated with the given context item.</summary>
        /// <returns>The <see cref="T:System.ComponentModel.PropertyDescriptor"></see> that describes the given context item; otherwise, null if there is no <see cref="T:System.ComponentModel.PropertyDescriptor"></see> responsible for the call.</returns>
        PropertyDescriptor PropertyDescriptor
        {
            get;
        }
    }

    /// <summary>Provides a unified way of converting types of values to other types, as well as for accessing standard values and subproperties.</summary>
    public class TypeConverter2:
        TypeConverter
    {

        /// <summary>Initializes a new instance of the <see cref="T:System.ComponentModel.TypeConverter"></see> class. </summary>
        public TypeConverter2()
        {
        }

        /// <summary>Returns whether this converter can convert an object of the given type to the type of this converter.</summary>
        /// <returns>true if this converter can perform the conversion; otherwise, false.</returns>
        /// <param name="sourceType">A <see cref="T:System.Type"></see> that represents the type you want to convert from. </param>
        public bool CanConvertFrom(Type sourceType)
        {
            return CanConvertFrom(null, sourceType);
        }

        /// <summary>Returns whether this converter can convert an object of the given type to the type of this converter, using the specified context.</summary>
        /// <returns>true if this converter can perform the conversion; otherwise, false.</returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        /// <param name="sourceType">A <see cref="T:System.Type"></see> that represents the type you want to convert from. </param>
        public virtual bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            if (sourceType==typeof(InstanceDescriptor))
                return true;

            return false;
        }

        /// <summary>Returns whether this converter can convert the object to the specified type.</summary>
        /// <returns>true if this converter can perform the conversion; otherwise, false.</returns>
        /// <param name="destinationType">A <see cref="T:System.Type"></see> that represents the type you want to convert to. </param>
        public bool CanConvertTo(Type destinationType)
        {
            return CanConvertTo(null, destinationType);
        }

        /// <summary>Returns whether this converter can convert the object to the specified type, using the specified context.</summary>
        /// <returns>true if this converter can perform the conversion; otherwise, false.</returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        /// <param name="destinationType">A <see cref="T:System.Type"></see> that represents the type you want to convert to. </param>
        public virtual bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            return (destinationType==typeof(string));
        }

        /// <summary>Converts the given value to the type of this converter.</summary>
        /// <returns>An <see cref="T:System.Object"></see> that represents the converted value.</returns>
        /// <param name="value">The <see cref="T:System.Object"></see> to convert. </param>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        public object ConvertFrom(object value)
        {
            return this.ConvertFrom(null, CultureInfo.CurrentCulture, value);
        }

        /// <summary>Converts the given object to the type of this converter, using the specified context and culture information.</summary>
        /// <returns>An <see cref="T:System.Object"></see> that represents the converted value.</returns>
        /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo"></see> to use as the current culture. </param>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        /// <param name="value">The <see cref="T:System.Object"></see> to convert. </param>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        public virtual object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            InstanceDescriptor descriptor1=value as InstanceDescriptor;
            if (descriptor1==null)
                throw GetConvertFromException(value);

            return descriptor1.Invoke();
        }

        /// <summary>Converts the given string to the type of this converter, using the invariant culture.</summary>
        /// <returns>An <see cref="T:System.Object"></see> that represents the converted text.</returns>
        /// <param name="text">The <see cref="T:System.String"></see> to convert. </param>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        public object ConvertFromInvariantString(string text)
        {
            return ConvertFromString(null, CultureInfo.InvariantCulture, text);
        }

        /// <summary>Converts the given string to the type of this converter, using the invariant culture.</summary>
        /// <returns>An <see cref="T:System.Object"></see> that represents the converted text.</returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        /// <param name="text">The <see cref="T:System.String"></see> to convert. </param>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        public object ConvertFromInvariantString(ITypeDescriptorContext context, string text)
        {
            return ConvertFromString(context, CultureInfo.InvariantCulture, text);
        }

        /// <summary>Converts the specified text to an object.</summary>
        /// <returns>An <see cref="T:System.Object"></see> that represents the converted text.</returns>
        /// <param name="text">The text representation of the object to convert. </param>
        /// <exception cref="T:System.NotSupportedException">The string cannot be converted into the appropriate object. </exception>
        public object ConvertFromString(string text)
        {
            return ConvertFrom(null, null, text);
        }

        /// <summary>Converts the given text to an object, using the specified context.</summary>
        /// <returns>An <see cref="T:System.Object"></see> that represents the converted text.</returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        /// <param name="text">The <see cref="T:System.String"></see> to convert. </param>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        public object ConvertFromString(ITypeDescriptorContext context, string text)
        {
            return ConvertFrom(context, CultureInfo.CurrentCulture, text);
        }

        /// <summary>Converts the given text to an object, using the specified context and culture information.</summary>
        /// <returns>An <see cref="T:System.Object"></see> that represents the converted text.</returns>
        /// <param name="culture">A <see cref="T:System.Globalization.CultureInfo"></see>. If null is passed, the current culture is assumed. </param>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        /// <param name="text">The <see cref="T:System.String"></see> to convert. </param>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        public object ConvertFromString(ITypeDescriptorContext context, CultureInfo culture, string text)
        {
            return ConvertFrom(context, culture, text);
        }

        /// <summary>Converts the given value object to the specified type, using the arguments.</summary>
        /// <returns>An <see cref="T:System.Object"></see> that represents the converted value.</returns>
        /// <param name="destinationType">The <see cref="T:System.Type"></see> to convert the value parameter to. </param>
        /// <param name="value">The <see cref="T:System.Object"></see> to convert. </param>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        /// <exception cref="T:System.ArgumentNullException">The destinationType parameter is null. </exception>
        public object ConvertTo(object value, Type destinationType)
        {
            return ConvertTo(null, null, value, destinationType);
        }

        /// <summary>Converts the given value object to the specified type, using the specified context and culture information.</summary>
        /// <returns>An <see cref="T:System.Object"></see> that represents the converted value.</returns>
        /// <param name="culture">A <see cref="T:System.Globalization.CultureInfo"></see>. If null is passed, the current culture is assumed. </param>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        /// <param name="destinationType">The <see cref="T:System.Type"></see> to convert the value parameter to. </param>
        /// <param name="value">The <see cref="T:System.Object"></see> to convert. </param>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        /// <exception cref="T:System.ArgumentNullException">The destinationType parameter is null. </exception>
        public virtual object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType==null)
            {
                throw new ArgumentNullException("destinationType");
            }
            if (destinationType!=typeof(string))
            {
                throw this.GetConvertToException(value, destinationType);
            }
            if (value==null)
            {
                return string.Empty;
            }
            if ((culture!=null)&&(culture!=CultureInfo.CurrentCulture))
            {
                IFormattable formattable1=value as IFormattable;
                if (formattable1!=null)
                {
                    return formattable1.ToString(null, culture);
                }
            }
            return value.ToString();
        }

        /// <summary>Converts the specified value to a culture-invariant string representation.</summary>
        /// <returns>A <see cref="T:System.String"></see> that represents the converted value.</returns>
        /// <param name="value">The <see cref="T:System.Object"></see> to convert. </param>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        public string ConvertToInvariantString(object value)
        {
            return this.ConvertToString(null, CultureInfo.InvariantCulture, value);
        }

        /// <summary>Converts the specified value to a culture-invariant string representation, using the specified context.</summary>
        /// <returns>A <see cref="T:System.String"></see> that represents the converted value.</returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        /// <param name="value">The <see cref="T:System.Object"></see> to convert. </param>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        public string ConvertToInvariantString(ITypeDescriptorContext context, object value)
        {
            return this.ConvertToString(context, CultureInfo.InvariantCulture, value);
        }

        /// <summary>Converts the specified value to a string representation.</summary>
        /// <returns>An <see cref="T:System.Object"></see> that represents the converted value.</returns>
        /// <param name="value">The <see cref="T:System.Object"></see> to convert. </param>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        public string ConvertToString(object value)
        {
            return (string)ConvertTo(null, CultureInfo.CurrentCulture, value, typeof(string));
        }

        /// <summary>Converts the given value to a string representation, using the given context.</summary>
        /// <returns>An <see cref="T:System.Object"></see> that represents the converted value.</returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        /// <param name="value">The <see cref="T:System.Object"></see> to convert. </param>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        public string ConvertToString(ITypeDescriptorContext context, object value)
        {
            return (string)ConvertTo(context, CultureInfo.CurrentCulture, value, typeof(string));
        }

        /// <summary>Converts the given value to a string representation, using the specified context and culture information.</summary>
        /// <returns>An <see cref="T:System.Object"></see> that represents the converted value.</returns>
        /// <param name="culture">A <see cref="T:System.Globalization.CultureInfo"></see>. If null is passed, the current culture is assumed. </param>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        /// <param name="value">The <see cref="T:System.Object"></see> to convert. </param>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        public string ConvertToString(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            return (string)ConvertTo(context, culture, value, typeof(string));
        }

        /// <summary>Re-creates an <see cref="T:System.Object"></see> given a set of property values for the object.</summary>
        /// <returns>An <see cref="T:System.Object"></see> representing the given <see cref="T:System.Collections.IDictionary"></see>, or null if the object cannot be created. This method always returns null.</returns>
        /// <param name="propertyValues">An <see cref="T:System.Collections.IDictionary"></see> that represents a dictionary of new property values. </param>
        public object CreateInstance(IDictionary propertyValues)
        {
            return CreateInstance(null, propertyValues);
        }

        /// <summary>Creates an instance of the type that this <see cref="T:System.ComponentModel.TypeConverter"></see> is associated with, using the specified context, given a set of property values for the object.</summary>
        /// <returns>An <see cref="T:System.Object"></see> representing the given <see cref="T:System.Collections.IDictionary"></see>, or null if the object cannot be created. This method always returns null.</returns>
        /// <param name="propertyValues">An <see cref="T:System.Collections.IDictionary"></see> of new property values. </param>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        public virtual object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues)
        {
            return null;
        }

        /// <summary>Returns an exception to throw when a conversion cannot be performed.</summary>
        /// <returns>An <see cref="T:System.Exception"></see> that represents the exception to throw when a conversion cannot be performed.</returns>
        /// <param name="value">The <see cref="T:System.Object"></see> to convert, or null if the object is not available. </param>
        /// <exception cref="T:System.NotSupportedException">Automatically thrown by this method. </exception>
        protected Exception GetConvertFromException(object value)
        {
            string text1;
            if (value==null)
            {
                text1="(null)";
            } else
            {
                text1=value.GetType().FullName;
            }
            throw new NotSupportedException(string.Format("{0} cannot convert from {1}.", new object[] { base.GetType().Name, text1 }));
        }

        /// <summary>Returns an exception to throw when a conversion cannot be performed.</summary>
        /// <returns>An <see cref="T:System.Exception"></see> that represents the exception to throw when a conversion cannot be performed.</returns>
        /// <param name="destinationType">A <see cref="T:System.Type"></see> that represents the type the conversion was trying to convert to. </param>
        /// <param name="value">The <see cref="T:System.Object"></see> to convert, or null if the object is not available. </param>
        /// <exception cref="T:System.NotSupportedException">Automatically thrown by this method. </exception>
        protected Exception GetConvertToException(object value, Type destinationType)
        {
            string text1;
            if (value==null)
            {
                text1="(null)";
            } else
            {
                text1=value.GetType().FullName;
            }
            throw new NotSupportedException(string.Format("'{0}' is unable to convert '{1}' to '{2}'.", new object[] { base.GetType().Name, text1, destinationType.FullName }));
        }

        /// <summary>Returns whether changing a value on this object requires a call to the <see cref="M:System.ComponentModel.TypeConverter.CreateInstance(System.Collections.IDictionary)"></see> method to create a new value.</summary>
        /// <returns>true if changing a property on this object requires a call to <see cref="M:System.ComponentModel.TypeConverter.CreateInstance(System.Collections.IDictionary)"></see> to create a new value; otherwise, false.</returns>
        public bool GetCreateInstanceSupported()
        {
            return GetCreateInstanceSupported(null);
        }

        /// <summary>Returns whether changing a value on this object requires a call to <see cref="M:System.ComponentModel.TypeConverter.CreateInstance(System.Collections.IDictionary)"></see> to create a new value, using the specified context.</summary>
        /// <returns>true if changing a property on this object requires a call to <see cref="M:System.ComponentModel.TypeConverter.CreateInstance(System.Collections.IDictionary)"></see> to create a new value; otherwise, false.</returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        public virtual bool GetCreateInstanceSupported(ITypeDescriptorContext context)
        {
            return false;
        }

        /// <summary>Returns a collection of properties for the type of array specified by the value parameter.</summary>
        /// <returns>A <see cref="T:System.ComponentModel.PropertyDescriptorCollection"></see> with the properties that are exposed for this data type, or null if there are no properties.</returns>
        /// <param name="value">An <see cref="T:System.Object"></see> that specifies the type of array for which to get properties. </param>
        public PropertyDescriptorCollection GetProperties(object value)
        {
            return GetProperties(null, value);
        }

        /// <summary>Returns a collection of properties for the type of array specified by the value parameter, using the specified context.</summary>
        /// <returns>A <see cref="T:System.ComponentModel.PropertyDescriptorCollection"></see> with the properties that are exposed for this data type, or null if there are no properties.</returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        /// <param name="value">An <see cref="T:System.Object"></see> that specifies the type of array for which to get properties. </param>
        public PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value)
        {
//            return GetProperties(context, value, new Attribute[] { BrowsableAttribute.Yes });
            return null;
        }

        /// <summary>Returns a collection of properties for the type of array specified by the value parameter, using the specified context and attributes.</summary>
        /// <returns>A <see cref="T:System.ComponentModel.PropertyDescriptorCollection"></see> with the properties that are exposed for this data type, or null if there are no properties.</returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        /// <param name="attributes">An array of type <see cref="T:System.Attribute"></see> that is used as a filter. </param>
        /// <param name="value">An <see cref="T:System.Object"></see> that specifies the type of array for which to get properties. </param>
        public virtual PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            return null;
        }

        /// <summary>Returns whether this object supports properties.</summary>
        /// <returns>true if <see cref="M:System.ComponentModel.TypeConverter.GetProperties(System.Object)"></see> should be called to find the properties of this object; otherwise, false.</returns>
        public bool GetPropertiesSupported()
        {
            return GetPropertiesSupported(null);
        }

        /// <summary>Returns whether this object supports properties, using the specified context.</summary>
        /// <returns>true if <see cref="M:System.ComponentModel.TypeConverter.GetProperties(System.Object)"></see> should be called to find the properties of this object; otherwise, false.</returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        public virtual bool GetPropertiesSupported(ITypeDescriptorContext context)
        {
            return false;
        }

        /// <summary>Returns a collection of standard values from the default context for the data type this type converter is designed for.</summary>
        /// <returns>A <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection"></see> containing a standard set of valid values, or null if the data type does not support a standard set of values.</returns>
        public ICollection GetStandardValues()
        {
            return GetStandardValues(null);
        }

        /// <summary>Returns a collection of standard values for the data type this type converter is designed for when provided with a format context.</summary>
        /// <returns>A <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection"></see> that holds a standard set of valid values, or null if the data type does not support a standard set of values.</returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context that can be used to extract additional information about the environment from which this converter is invoked. This parameter or properties of this parameter can be null. </param>
        public virtual /*TypeConverter.StandardValuesCollection*/ICollection GetStandardValues(ITypeDescriptorContext context)
        {
            return null;
        }

        /// <summary>Returns whether the collection of standard values returned from <see cref="M:System.ComponentModel.TypeConverter.GetStandardValues"></see> is an exclusive list.</summary>
        /// <returns>true if the <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection"></see> returned from <see cref="M:System.ComponentModel.TypeConverter.GetStandardValues"></see> is an exhaustive list of possible values; false if other values are possible.</returns>
        public bool GetStandardValuesExclusive()
        {
            return this.GetStandardValuesExclusive(null);
        }

        /// <summary>Returns whether the collection of standard values returned from <see cref="M:System.ComponentModel.TypeConverter.GetStandardValues"></see> is an exclusive list of possible values, using the specified context.</summary>
        /// <returns>true if the <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection"></see> returned from <see cref="M:System.ComponentModel.TypeConverter.GetStandardValues"></see> is an exhaustive list of possible values; false if other values are possible.</returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        public virtual bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return false;
        }

        /// <summary>Returns whether this object supports a standard set of values that can be picked from a list.</summary>
        /// <returns>true if <see cref="M:System.ComponentModel.TypeConverter.GetStandardValues"></see> should be called to find a common set of values the object supports; otherwise, false.</returns>
        public bool GetStandardValuesSupported()
        {
            return GetStandardValuesSupported(null);
        }

        /// <summary>Returns whether this object supports a standard set of values that can be picked from a list, using the specified context.</summary>
        /// <returns>true if <see cref="M:System.ComponentModel.TypeConverter.GetStandardValues"></see> should be called to find a common set of values the object supports; otherwise, false.</returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        public virtual bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return false;
        }

        /// <summary>Returns whether the given value object is valid for this type.</summary>
        /// <returns>true if the specified value is valid for this object; otherwise, false.</returns>
        /// <param name="value">The object to test for validity. </param>
        public bool IsValid(object value)
        {
            return IsValid(null, value);
        }

        /// <summary>Returns whether the given value object is valid for this type and for the specified context.</summary>
        /// <returns>true if the specified value is valid for this object; otherwise, false.</returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        /// <param name="value">The <see cref="T:System.Object"></see> to test for validity. </param>
        public virtual bool IsValid(ITypeDescriptorContext context, object value)
        {
            return true;
        }
/*
        /// <summary>Sorts a collection of properties.</summary>
        /// <returns>A <see cref="T:System.ComponentModel.PropertyDescriptorCollection"></see> that contains the sorted properties.</returns>
        /// <param name="names">An array of names in the order you want the properties to appear in the collection. </param>
        /// <param name="props">A <see cref="T:System.ComponentModel.PropertyDescriptorCollection"></see> that has the properties to sort. </param>
        protected PropertyDescriptorCollection SortProperties(PropertyDescriptorCollection props, string[] names)
        {
            props.Sort(names);
            return props;
        }
*/
    }

    /// <summary>Provides a type converter to convert <see cref="T:System.Enum"></see> objects to and from various other representations.</summary>
    public class EnumConverter:
        TypeConverter2
    {

        /// <summary>Initializes a new instance of the <see cref="T:System.ComponentModel.EnumConverter"></see> class for the given type.</summary>
        /// <param name="type">A <see cref="T:System.Type"></see> that represents the type of enumeration to associate with this enumeration converter. </param>
        public EnumConverter(Type type)
        {
            _Type=type;
        }

        /// <summary>Gets a value indicating whether this converter can convert an object in the given source type to an enumeration object using the specified context.</summary>
        /// <returns>true if this converter can perform the conversion; otherwise, false.</returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        /// <param name="sourceType">A <see cref="T:System.Type"></see> that represents the type you wish to convert from. </param>
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            if ((sourceType!=typeof(string))&&(sourceType!=typeof(Enum[])))
            {
                return base.CanConvertFrom(context, sourceType);
            }
            return true;
        }

        /// <summary>Gets a value indicating whether this converter can convert an object to the given destination type using the context.</summary>
        /// <returns>true if this converter can perform the conversion; otherwise, false.</returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        /// <param name="destinationType">A <see cref="T:System.Type"></see> that represents the type you wish to convert to. </param>
        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            if ((destinationType!=typeof(InstanceDescriptor))&&(destinationType!=typeof(Enum[])))
            {
                return base.CanConvertTo(context, destinationType);
            }
            return true;
        }

        /// <summary>Converts the specified value object to an enumeration object.</summary>
        /// <returns>An <see cref="T:System.Object"></see> that represents the converted value.</returns>
        /// <param name="culture">An optional <see cref="T:System.Globalization.CultureInfo"></see>. If not supplied, the current culture is assumed. </param>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        /// <param name="value">The <see cref="T:System.Object"></see> to convert. </param>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        /// <exception cref="T:System.FormatException">value is not a valid value for the target type. </exception>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                try
                {
                    string text1=(string)value;
                    if (text1.IndexOf(',')!=-1)
                    {
                        long num1=0;
                        string[] textArray1=text1.Split(new char[] { ',' });
                        foreach (string text2 in textArray1)
                        {
                            num1|=Convert.ToInt64((Enum)Enum.Parse(_Type, text2, true), culture);
                        }
                        return Enum.ToObject(_Type, num1);
                    }
                    return Enum.Parse(_Type, text1, true);
                } catch (Exception exception1)
                {
                    throw new FormatException(string.Format("{0} is not a valid value for {1}.", new object[] { (string)value, _Type.Name }), exception1);
                }
            }
            if (!(value is Enum[]))
            {
                return base.ConvertFrom(context, culture, value);
            }
            long num2=0;
            foreach (Enum enum1 in ((Enum[])value))
            {
                num2|=Convert.ToInt64(enum1, culture);
            }
            return Enum.ToObject(_Type, num2);
        }

        /// <summary>Converts the given value object to the specified destination type.</summary>
        /// <returns>An <see cref="T:System.Object"></see> that represents the converted value.</returns>
        /// <param name="culture">An optional <see cref="T:System.Globalization.CultureInfo"></see>. If not supplied, the current culture is assumed. </param>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        /// <param name="destinationType">The <see cref="T:System.Type"></see> to convert the value to. </param>
        /// <param name="value">The <see cref="T:System.Object"></see> to convert. </param>
        /// <exception cref="T:System.ArgumentException">value is not a valid value for the enumeration. </exception>
        /// <exception cref="T:System.ArgumentNullException">destinationType is null. </exception>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType==null)
            {
                throw new ArgumentNullException("destinationType");
            }
            if ((destinationType==typeof(string))&&(value!=null))
            {
                Type type1=Enum.GetUnderlyingType(_Type);
                if ((value is IConvertible)&&(value.GetType()!=type1))
                {
                    value=((IConvertible)value).ToType(type1, culture);
                }
                if (!_Type.IsDefined(typeof(FlagsAttribute), false)&&!Enum.IsDefined(_Type, value))
                {
                    throw new ArgumentException(string.Format("The value '{0}' is not a valid value for the enum '{1}'.", new object[] { value.ToString(), _Type.Name }));
                }
//                return Enum.Format(_Type, value, "G");
                return string.Format("G", value);
            }
            if ((destinationType==typeof(InstanceDescriptor))&&(value!=null))
            {
                string text1=base.ConvertToInvariantString(context, value);
                if (_Type.IsDefined(typeof(FlagsAttribute), false)&&(text1.IndexOf(',')!=-1))
                {
                    Type type2=Enum.GetUnderlyingType(_Type);
                    if (value is IConvertible)
                    {
                        object obj1=((IConvertible)value).ToType(type2, culture);
                        MethodInfo info1=typeof(Enum).GetMethod("ToObject", new Type[] { typeof(Type), type2 });
                        if (info1!=null)
                        {
                            return new InstanceDescriptor(info1, new object[] { _Type, obj1 });
                        }
                    }
                } else
                {
                    FieldInfo info2=_Type.GetField(text1);
                    if (info2!=null)
                    {
                        return new InstanceDescriptor(info2, null);
                    }
                }
            }
            if ((destinationType!=typeof(Enum[]))||(value==null))
            {
                return base.ConvertTo(context, culture, value, destinationType);
            }
            if (!_Type.IsDefined(typeof(FlagsAttribute), false))
            {
                return new Enum[] { ((Enum)Enum.ToObject(_Type, value)) };
            }

            throw new NotSupportedException();

/*
            List<Enum> list1=new List<Enum>();
            Array array1=Enum.GetValues(_Type);
            long[] numArray1=new long[array1.Length];
            for (int num1=0; num1<array1.Length; num1++)
            {
                numArray1[num1]=Convert.ToInt64((Enum)array1.GetValue(num1), culture);
            }
            long num2=Convert.ToInt64((Enum)value, culture);
            bool flag1=true;
            while (flag1)
            {
                flag1=false;
                foreach (long num3 in numArray1)
                {
                    if (((num3!=0)&&((num3&num2)==num3))||(num3==num2))
                    {
                        list1.Add((Enum)Enum.ToObject(_Type, num3));
                        flag1=true;
                        num2&=~num3;
                        break;
                    }
                }
                if (num2==0)
                {
                    break;
                }
            }
            if (!flag1&&(num2!=0))
            {
                list1.Add((Enum)Enum.ToObject(_Type, num2));
            }
            return list1.ToArray();
*/
        }

        /// <summary>Specifies the type of the enumerator this converter is associated with.</summary>
        /// <returns>The type of the enumerator this converter is associated with.</returns>
        protected Type EnumType
        {
            get
            {
                return _Type;
            }
        }

        private Type _Type;
    }
}
#endif
